// 60分
#include <bits/stdc++.h>
using namespace std;
int a[100010];
int san[100010];
int backup[100010];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] %= 3;
  }
  for (int i = 3; i <= n; i++) {
    san[i] = (a[i] + a[i - 1] + a[i - 2]) % 3;
    backup[i] = san[i]; // 备份
  }
  long long ans = LLONG_MAX;

  // 枚举第一个位置，第二个位置的调整次数
  for (int i = 0; i <= 2; i++) {
    long long ci = i;
    copy(backup + 1, backup + n + 1, san + 1); // 恢复原状
    san[3] = (san[3] + i) % 3;
    for (int j = 0; j <= 2; j++) {
      san[3] = (san[3] + j) % 3;
      san[4] = (san[4] + j) % 3;
      ci += j;
      for (int k = 3; k <= n; k++) {
        int delta = (3 - san[k]) % 3;
        ci += delta;
        san[k + 1] = (san[k + 1] + delta) % 3;
        san[k + 2] = (san[k + 2] + delta) % 3;
      }
      ans = min(ans, ci);
    }
  }
  cout << ans;

  return 0;
}